<div>
	<!-- widget content -->
	<div class="widget-body">

		<form action="" method="post" id="checkout-form" class="smart-form">
			<header>
				<h2>
					选择备份文件
					<button class="close" data-dismiss="modal">x</button>
				</h2>
			</header>
			<fieldset>
				<div id="dialog-alert"></div>
				<div class="row">
					<label class="label col col-2"><label style="color: red">*</label>备份文件</label>
					<section class="col col-12">
						<label class="select"> <select class="required "
							id="backupFileId" name="backupFileId">
								<option value="">请选择备份文件</option>
						</select><i></i>
						</label>
					</section>
				</div>
			</fieldset>
		</form>
	</div>
	<!-- end widget content -->

</div>
<div class="modal-footer">

	<button type="button" class="btn btn-default btn-sm"
		data-dismiss="modal">取消</button>
	<button type="submit" class="btn btn-primary btn-sm" id="submitbtn">
		确认</button>
</div>
<script>
	pageSetUp();

	var backupFileId, $backupFileId;

	var pagefunction = function() {
		sendGet("/upm_manager/v1.0/backupfiles?serv="
				+ getSession("serviceUpsqlId") + "&site="
				+ getSession("siteId"), fillSelect_backupfile, DialogAlert,
				null);

		var errorClass = 'invalid';
		var errorElement = 'em';
		var option = {
			errorClass : errorClass,
			errorElement : errorElement,
			highlight : function(element) {
				$(element).parent().removeClass('state-success').addClass(
						"state-error");
				$(element).removeClass('valid');
			},
			unhighlight : function(element) {
				$(element).parent().removeClass("state-error").addClass(
						'state-success');
				$(element).addClass('valid');
			},
			// Rules for form validation
			// Messages for form validation
			messages : {
				name : {
					required : '请输入区域名称'
				},
				description : {
					required : '请输入描述'
				},
				backupStorage : {
					required : '请选择备份存储'
				}
			},
			errorPlacement : function(error, element) {
				if ($(element).next("div").hasClass("tooltip")) {
					$(element).attr("data-original-title", $(error).text())
							.tooltip("show");
				} else {
					$(element).attr("title", $(error).text()).tooltip("show");
				}
			},
			submitHandler : function(form) {
				var data = $('#checkout-form').serializeArray();
				var jsonData = {
					backupFileId : data[0].value
				};
				var s = $("#jqgrid").jqGrid('getGridParam', 'selarrrow');
				var unitId = $("#jqgrid").jqGrid('getRowData', s).id;
				//在这里调用ajax方法提交
				sendPut("/upm_manager/v1.0/units/" + unitId + "/restore",
						postSuccess, DialogAlert, JSON.stringify(jsonData),
						null);
			}
		};
		$('#checkout-form').validate(option);
	};
	loadScript("js/plugin/jquery-form/jquery-form.min.js", pagefunction);

	function fillSelect_backupfile(data) {
		$backupFileId = $("#backupFileId").selectize({
			valueField : 'id',
			labelField : 'name',
			searchField : 'name',
			create : false,
			sortField : {
				field : 'name'
			},
			options : []
		});
		backupFileId = $backupFileId[0].selectize;
		backupFileId.clearOptions();
		$.each(data.data, function(k, v) {
			backupFileId.addOption(v);
			backupFileId.setValue([ v.id ]);
		});
	}

	$('#submitbtn').click(function() {
		DialogAlertClear();
		$('#checkout-form').submit();
	});
	function postSuccess(data) {
		//提交成功的方法
		$("#myModal").modal('toggle');
		sendGet("/upm_manager/v1.0/units?serv=" + getSession("serviceUpsqlId")
				+ '&subserv_type=upsql', reloadUnitGrid, ListAlert, null);
	}
</script>